import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.lcdui.*;
import java.util.*;

public class AudioPlayer extends Canvas implements CommandListener, PlayerListener, Runnable{
	private Player player;
	private VolumeControl vc;
	private FileManagerMIDlet filemanager;
	private ListContend list;
	private String url, filename;
	private Command play, pause, back, option, ok, cancel, stop;
	private int repeattime;
	private Form optionform;
	private TextField numplayback;
	private ChoiceGroup shutdown;
	private Display display;

	//Cac bien dung de tao visualization
	private int paintvalue1, newvalue1, paintvalue2, newvalue2, paintvalue3, newvalue3, paintvalue4, newvalue4, paintvalue5, newvalue5, paintvalue6, newvalue6, paintvalue7, newvalue7, paintvalue8, newvalue8, paintvalue9, newvalue9, paintvalue10, newvalue10;
	private int paintvalue11, newvalue11, paintvalue12, newvalue12, paintvalue13, newvalue13, paintvalue14, newvalue14, paintvalue15, newvalue15, paintvalue16, newvalue16, paintvalue17, newvalue17, paintvalue18, newvalue18, paintvalue19, newvalue19, paintvalue20, newvalue20;
	private int wp1, wp2, wp3, wp4, wp5, wp6, wp7, wp8, wp9, wp10, wp11, wp12, wp13, wp14, wp15, wp16, wp17, wp18, wp19, wp20;
	private int i, j;
	private Random rn;
	private boolean st, ready;

	public AudioPlayer(FileManagerMIDlet fm, ListContend list, String upurl, String musicfilename, Display display){
		setTitle(musicfilename);
		this.url = upurl;
		this.list = list;
		this.filemanager = fm;
		this.filename = musicfilename;
		this.display = display;
		play = new Command("Phat", Command.OK, 0);
		pause = new Command("T.Dung", Command.OK, 0);
		back = new Command("Tro ve", Command.BACK, 1);
		ok = new Command("Dong y",Command.OK,0);
		cancel = new Command("Huy",Command.CANCEL,0);
		option = new Command("Tuy chon phat", Command.OK, 1);		
		numplayback = new TextField("Nhap so lan ban muon phat lai", "0", 3,TextField.NUMERIC);
		shutdown = new ChoiceGroup("",Choice.MULTIPLE);
		shutdown.append("Thoat chuong trinh khi phat du so lan", null);	
		optionform = new Form("Tuy chon phat");
		optionform.append(shutdown);
		optionform.append(numplayback);		
		optionform.addCommand(ok);
		optionform.addCommand(cancel);
		optionform.setCommandListener(this);
		repeattime = 1;
		addCommand(play);
		addCommand(back);
		addCommand(option);	
		setCommandListener(this);
		try{			
			player = Manager.createPlayer(url + musicfilename);	
			player.addPlayerListener(this);
			player.realize();								
			player.prefetch();	
			vc = (VolumeControl) player.getControl("VolumeControl");
			if(vc != null){
				vc.setLevel(100);
			}			
		
		}
		catch(Exception e){}		
		new Thread(this).start();
		st = false;
		ready = true;
		rn = new Random();
		i = 0;			
	}

	protected void paint(Graphics graphics){
		graphics.setColor(0,0,0);
		graphics.fillRect(0, 0, getWidth(), getHeight());
		j = 150;
		for(i = getHeight(); i > paintvalue1; i -= 4){	
			graphics.setColor(j,j,255);
			if((i - paintvalue1) >= 4)		
				graphics.fillRect(4, i, 5, 3);
			else	
				graphics.fillRect(4, paintvalue1+3, 5, (i - paintvalue1));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(4, wp1, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue2; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue2) >= 4)
				graphics.fillRect(10, i, 5, 3);
			else
				graphics.fillRect(10, paintvalue2+3, 5, (i - paintvalue2));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(10, wp2, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue3; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue3) >= 4)
				graphics.fillRect(16, i, 5, 3);
			else
				graphics.fillRect(16, paintvalue3+3, 5, (i - paintvalue3));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(16, wp3, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue4; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue4) >= 4)
				graphics.fillRect(22, i, 5, 3);
			else
				graphics.fillRect(22, paintvalue4+3, 5, (i - paintvalue4));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(22, wp4, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue5; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue5) >= 4)
				graphics.fillRect(28, i, 5, 3);
			else
				graphics.fillRect(28, paintvalue5+3, 5, (i - paintvalue5));
			j -=8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(28, wp5, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue6; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue6) >= 4)
				graphics.fillRect(34, i, 5, 3);
			else
				graphics.fillRect(34, paintvalue6+3, 5, (i - paintvalue6));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(34, wp6, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue7; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue7) >= 4)
				graphics.fillRect(40, i, 5, 3);
			else
				graphics.fillRect(40, paintvalue7+3, 5, (i - paintvalue7));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(40, wp7, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue8; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue8) >= 4)
				graphics.fillRect(46, i, 5, 3);
			else
				graphics.fillRect(46, paintvalue8+3, 5, (i - paintvalue8));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(46, wp8, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue9; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue9) >= 4)
				graphics.fillRect(52, i, 5, 3);
			else
				graphics.fillRect(52, paintvalue9+3, 5, (i - paintvalue9));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(52, wp9, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue10; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue10) >= 4)
				graphics.fillRect(58, i, 5, 3);
			else
				graphics.fillRect(58, paintvalue10+3, 5, (i - paintvalue10));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(58, wp10, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue11; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue11) >= 4)
				graphics.fillRect(64, i, 5, 3);
			else
				graphics.fillRect(64, paintvalue11+3, 5, (i - paintvalue11));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(64, wp11, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue12; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue12) >= 4)
				graphics.fillRect(70, i, 5, 3);
			else
				graphics.fillRect(70, paintvalue12+3, 5, (i - paintvalue12));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(70, wp12, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue13; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue13) >= 4)
				graphics.fillRect(76, i, 5, 3);
			else
				graphics.fillRect(76, paintvalue13+3, 5, (i - paintvalue13));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(76, wp13, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue14; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue14) >= 4)
				graphics.fillRect(82, i, 5, 3);
			else
				graphics.fillRect(82, paintvalue14+3, 5, (i - paintvalue14));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(82, wp14, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue15; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue15) >= 4)
				graphics.fillRect(88, i, 5, 3);
			else
				graphics.fillRect(88, paintvalue15+3, 5, (i - paintvalue15));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(88, wp15, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue16; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue16) >= 4)
				graphics.fillRect(94, i, 5, 3);
			else
				graphics.fillRect(94, paintvalue16+3, 5, (i - paintvalue16));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(94, wp16, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue17; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue17) >= 4)
				graphics.fillRect(100, i, 5, 3);
			else
				graphics.fillRect(100, paintvalue17+3, 5, (i - paintvalue17));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(100, wp17, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue18; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue18) >= 4)
				graphics.fillRect(106, i, 5, 3);
			else
				graphics.fillRect(106, paintvalue18+3, 5, (i - paintvalue18));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(106, wp18, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue19; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue19) >= 4)
				graphics.fillRect(112, i, 5, 3);
			else
				graphics.fillRect(112, paintvalue19+3, 5, (i - paintvalue19));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(112, wp19, 5, 1);
		j = 150;
		for(i = getHeight(); i > paintvalue20; i -= 4){
			graphics.setColor(j,j,255);
			if((i - paintvalue20) >= 4)
				graphics.fillRect(118, i, 5, 3);
			else
				graphics.fillRect(118, paintvalue20+3, 5, (i - paintvalue20));
			j -= 8;
			if(j<0)
				j = 0;
		}
		graphics.setColor(255,255,255);
		graphics.fillRect(118, wp20, 5, 1);
		if(ready){
			graphics.setColor(0,0,0);
			graphics.fillRect(0, 0, getWidth(), getHeight());
		}
	}
	public void run(){			
		while(!st){		
		if(paintvalue2 > newvalue2){			
			paintvalue2 = newvalue2;
			if(paintvalue1 > paintvalue2 + 10){				
				newvalue1 = rn.nextInt(30);
				newvalue1 += paintvalue2 -15;				
			}
			if(wp2>= paintvalue2)
				wp2 = paintvalue2 + 1;	
			else
				wp2 += 1;		
			newvalue2 = rn.nextInt(getHeight());				
			while((newvalue2 > (getHeight() - getHeight()/3)) || (newvalue2 < getHeight()/2))
				newvalue2 = rn.nextInt(getHeight());			
		}
		else{
			wp2 += 1;
			paintvalue2 += 2;
					
		}	
		if(newvalue1 < 0)
				newvalue1 = 0;			
		if(paintvalue1 > newvalue1){			
			paintvalue1 = newvalue1;
			if(paintvalue3 > paintvalue1 + 10){				
				newvalue3 = rn.nextInt(30);
				newvalue3 += paintvalue1 -15;				
			}				
			if(wp1>= paintvalue1)
				wp1 = paintvalue1 + 1;
			else
				wp1 += 1;	
			newvalue1 = rn.nextInt(getHeight());
			while(newvalue1 < paintvalue2 - 15)
				newvalue1 = rn.nextInt(getHeight());
		}
		else{								
			wp1 += 1;
			paintvalue1 += 2;		
		}
		if(newvalue3 < 0)
				newvalue3 = 0;	
		if(paintvalue3 > newvalue3){			
			paintvalue3 = newvalue3;
			if(paintvalue4 > paintvalue3 + 10){				
				newvalue4 = rn.nextInt(30);
				newvalue4 += paintvalue3 -15;				
			}
			paintvalue3 = newvalue3;			
			if(wp3>= paintvalue3)
				wp3 = paintvalue3 +1;	
			else
				wp3 += 1;			
			newvalue3 = rn.nextInt(getHeight());
			while(newvalue3 < paintvalue1 - 15)
				newvalue3 = rn.nextInt(getHeight());
		}
		else{
			wp3 += 1;
			paintvalue3 += 2;			
		}
		if(newvalue4 < 0)
				newvalue4 = 0;
		if(paintvalue4 > newvalue4){						
			paintvalue4 = newvalue4;
			if(paintvalue5 > paintvalue4 + 10){				
				newvalue5 = rn.nextInt(30);
				newvalue5 += paintvalue4 -15;				
			}
			if(wp4>= paintvalue4)
				wp4 = paintvalue4 +1;	
			else
				wp4 += 1;
			newvalue4 = rn.nextInt(getHeight());
			while(newvalue4 < paintvalue3 - 15)
				newvalue4 = rn.nextInt(getHeight());
		}
		else{
			wp4 += 1;
			paintvalue4 += 2;			
		}
		if(newvalue5 < 0)
				newvalue5 = 0;
		if(paintvalue5 > newvalue5){			
			paintvalue5 = newvalue5;
			if(paintvalue6 > paintvalue5 + 5){
				newvalue6 = rn.nextInt(30);
				newvalue6 += paintvalue5 - 25;	
			}													
			if(wp5>= paintvalue5)
				wp5 = paintvalue5 +1;	
			else
				wp5 += 1;
			newvalue5 = rn.nextInt(getHeight());
			while(newvalue5 < paintvalue4 - 15)
				newvalue5 = rn.nextInt(getHeight());
		}
		else{
			wp5 += 1;
			paintvalue5 += 2;			
		}
		if(newvalue6 < 0)
				newvalue6 = 0;			
		if(paintvalue6 > newvalue6){												
			paintvalue6 = newvalue6;
			while((newvalue7 > paintvalue6)||(newvalue7 < paintvalue6-20))
					newvalue7 = rn.nextInt(getHeight());						
			if(wp6>= paintvalue6)
				wp6 = paintvalue6 +1;	
			else
				wp6 += 1;	
			newvalue6 = rn.nextInt(getHeight());
			while(newvalue6 < paintvalue5 - 25)
				newvalue6 = rn.nextInt(getHeight());
			
				
		}
		else{
			wp6 += 1;
			paintvalue6 += 2;			
		}
		if(newvalue7 < 0)
				newvalue7 = 0;
		if(paintvalue7 > newvalue7){			
			paintvalue7 = newvalue7;	
			if(paintvalue7 < (getHeight()/3-10))
				while(newvalue8 > paintvalue7)
					newvalue8 = rn.nextInt(getHeight());
			else{
				newvalue8 = rn.nextInt(40);
				newvalue8 = paintvalue7 + 30 - newvalue8;
			}				
			if(wp7>= paintvalue7)
				wp7 = paintvalue7+1;	
			else
				wp7 += 1;
			newvalue7 = rn.nextInt(getHeight());						
			while((newvalue7 > paintvalue6)||(newvalue7 < paintvalue6-20))
				newvalue7 = rn.nextInt(getHeight());
		}
		else{
			wp7 += 1;
			paintvalue7 += 2;				
		}
		if(newvalue8 < 0)
				newvalue8 = 0;
		if(paintvalue8 > newvalue8){			
			paintvalue8 = newvalue8;	
			if(paintvalue6 > paintvalue7)	
				while((newvalue9 > paintvalue6)||(newvalue9 < paintvalue7))
					newvalue9 = rn.nextInt(getHeight());						
			else
				while((newvalue9 < paintvalue6)||(newvalue9 > paintvalue7))
					newvalue9 = rn.nextInt(getHeight());			
			if(wp8>= paintvalue8)
				wp8 = paintvalue8 +1;	
			else
				wp8 += 1;
			newvalue8 = rn.nextInt(getHeight());
			if(paintvalue7 < (getHeight()/3-10))
				while(newvalue8 > paintvalue7)
					newvalue8 = rn.nextInt(getHeight());
			else{
				newvalue8 = rn.nextInt(30);
				newvalue8 = paintvalue7 + 20 - newvalue8;
			}			
		}
		else{
			wp8 += 1;
			paintvalue8 += 2;			
		}	
		if(newvalue9 < 0)
				newvalue9 = 0;	
		if(paintvalue9 > newvalue9){			
			paintvalue9 = newvalue9;
			if(paintvalue10 > paintvalue9)
				while((newvalue10 > paintvalue9 + 30)||((newvalue10 < paintvalue9 - 20)))
					newvalue10 = rn.nextInt(getHeight());
			if(wp9>= paintvalue9)
				wp9 = paintvalue9 +1;	
			else
				wp9 += 1;
			newvalue9 = rn.nextInt(getHeight());
			if(paintvalue6 > paintvalue7)	
				while((newvalue9 > paintvalue6)||(newvalue9 < paintvalue7))
					newvalue9 = rn.nextInt(getHeight());						
			else
				while((newvalue9 < paintvalue6)||(newvalue9 > paintvalue7))
					newvalue9 = rn.nextInt(getHeight());			
		}
		else{
			wp9 += 1;
			paintvalue9 += 2;			
		}
		if(paintvalue10 > newvalue10){
			if(newvalue10 < 0)
				newvalue10 = 0;
			paintvalue10 = newvalue10;
			if(wp10>= paintvalue10)
				wp10= paintvalue10 +1;
			else
				wp10 += 1;	
			newvalue10 = rn.nextInt(getHeight());
			while((newvalue10 > paintvalue9 + 30)||((newvalue10 < paintvalue9 - 20)))
				newvalue10 = rn.nextInt(getHeight());			
		}
		else{
			wp10 += 1;
			paintvalue10 += 2;			
		}
		if(newvalue11 < 0)
				newvalue11 = 0;
		if(paintvalue11 > newvalue11){			
			paintvalue11 = newvalue11;
			if(wp11>= paintvalue11)
				wp11 = paintvalue11 +1;
			else
				wp11 += 1;	
			newvalue11 = rn.nextInt(getHeight());
			while(newvalue11>(getHeight() - (getHeight()/3)))
				newvalue11 = rn.nextInt(getHeight());
		}
		else{
			wp11 += 1;
			paintvalue11 += 2;			
		}
		if(newvalue12 < 0)
				newvalue12 = 0;
		if(paintvalue12 > newvalue12){			
			paintvalue12 = newvalue12;
			if(wp12>= paintvalue12)
				wp12 = paintvalue12 +1;
			else
				wp12 += 1;	
			newvalue12 = rn.nextInt(getHeight());
			while(newvalue12>(getHeight() - (getHeight()/3)))
				newvalue12 = rn.nextInt(getHeight());
		}
		else{
			wp12 += 1;
			paintvalue12 += 2;			
		}
		if(newvalue13 < 0)
				newvalue13 = 0;
		if(paintvalue13 > newvalue13){			
			paintvalue13 = newvalue13;
			if(wp13>= paintvalue13)
				wp13 = paintvalue13 +1;
				wp13 += 1;	
			newvalue13 = rn.nextInt(getHeight());
			while(newvalue13>(getHeight() - (getHeight()/3)))
				newvalue13 = rn.nextInt(getHeight());
		}
		else{
			wp13 += 1;
			paintvalue13 += 2;			
		}
		if(newvalue14 < 0)
				newvalue14 = 0;
		if(paintvalue14 > newvalue14){			
			paintvalue14 = newvalue14;
			if(wp14>= paintvalue14)
				wp14 = paintvalue14 +1;
			else
				wp14 += 1;	
			newvalue14 = rn.nextInt(getHeight());
			while(newvalue14>(getHeight() - (getHeight()/3)))
				newvalue14= rn.nextInt(getHeight());
		}
		else{
			wp14 += 1;
			paintvalue14 += 2;			
		}
		if(newvalue15 < 0)
				newvalue15 = 0;
		if(paintvalue15 > newvalue15){			
			paintvalue15 = newvalue15;
			if(wp15>= paintvalue15)
				wp15 = paintvalue15 +1;
			else
				wp15 += 1;	
			newvalue15 = rn.nextInt(getHeight());
			while(newvalue15>(getHeight() - (getHeight()/3)))
				newvalue15 = rn.nextInt(getHeight());
		}
		else{
			wp15 += 1;
			paintvalue15 += 2;			
		}
		if(newvalue16 < 0)
				newvalue16 = 0;
		if(paintvalue16 > newvalue16){			
			paintvalue16 = newvalue16;
			if(wp16>= paintvalue16)
				wp16 = paintvalue16 +1;
			else
				wp16 += 1;	
			newvalue16 = rn.nextInt(getHeight());
			while(newvalue16>(getHeight() - (getHeight()/3)))
				newvalue16 = rn.nextInt(getHeight());
		}
		else{
			wp16 += 1;
			paintvalue16 += 2;			
		}
		if(newvalue17 < 0)
				newvalue17 = 0;
		if(paintvalue17 > newvalue17){			
			paintvalue17 = newvalue17;
			if(wp17>= paintvalue17)
				wp17 = paintvalue17 +1;
			else
				wp17 += 1;	
			newvalue17 = rn.nextInt(getHeight());
			while(newvalue17>(getHeight() - (getHeight()/3)))
				newvalue17 = rn.nextInt(getHeight());
		}
		else{
			wp17 += 1;
			paintvalue17 += 2;			
		}
		if(paintvalue18 > newvalue18){
			paintvalue18 = newvalue18;
			if(paintvalue19 > paintvalue18 + 10){				
				newvalue19 = rn.nextInt(20);
				newvalue19 += paintvalue18;				
			}
			if(wp18>= paintvalue18)
				wp18 = paintvalue18 +1;
			else
				wp18 += 1;	
			newvalue18 = rn.nextInt(getHeight());
			while((newvalue18 > (getHeight() - (getHeight()/3))) || (newvalue18 < (getHeight()/2)))
				newvalue18 = rn.nextInt(getHeight());
		}
		else{
			wp18 += 1;
			paintvalue18 += 2;			
		}
		if(paintvalue19 > newvalue19){
			paintvalue19 = newvalue19;
			if(paintvalue20 > paintvalue19 + 10){				
				newvalue20 = rn.nextInt(20);
				newvalue20 += paintvalue19;				
			}
			if(wp19>= paintvalue19)
				wp19 = paintvalue19 +1;
			else
				wp19 += 1;	
			newvalue19 = rn.nextInt(getHeight());
			while(newvalue19 < paintvalue18)
				newvalue19 = rn.nextInt(getHeight());
		}
		else{
			wp19 += 1;
			paintvalue19 += 2;			
		}
		if(paintvalue20 > newvalue20){
			paintvalue20 = newvalue20;
			if(wp20>= paintvalue20)
				wp20 = paintvalue20 +1;
			else
				wp20 += 1;	
			newvalue20 = rn.nextInt(getHeight());
			while(newvalue20 < paintvalue19)
				newvalue20 = rn.nextInt(getHeight());
		}
		else{
			wp20 += 1;
			paintvalue20 += 2;			
		}
		try{		
			Thread.sleep(40);
		
		}
		catch(Exception e){}	
		repaint();
		}
		while(st){
			paintvalue1 += 2;
			wp1 += 1;
			if(paintvalue1 == getHeight())
				paintvalue1 = getHeight();
			if(wp1 == getHeight())
				wp1 = getHeight();
			paintvalue2 += 2;
			wp2 += 1;
			if(paintvalue2 == getHeight())
				paintvalue2 = getHeight();
			if(wp2 == getHeight())
				wp2 = getHeight();
			paintvalue3 += 2;
			wp3 += 1;
			if(paintvalue3 == getHeight())
				paintvalue3 = getHeight();
			if(wp3 == getHeight())
				wp3 = getHeight();
			paintvalue4 += 2;
			wp4 += 1;
			if(paintvalue4 == getHeight())
				paintvalue4 = getHeight();
			if(wp4 == getHeight())
				wp4 = getHeight();
			paintvalue5 += 2;
			wp5 += 1;
			if(paintvalue5 == getHeight())
				paintvalue5 = getHeight();
			if(wp5 == getHeight())
				wp5 = getHeight();
			paintvalue6 += 2;
			wp6 += 1;
			if(paintvalue6 == getHeight())
				paintvalue6 = getHeight();
			if(wp6 == getHeight())
				wp6 = getHeight();
			paintvalue7 += 2;
			wp7 += 1;
			if(paintvalue7 == getHeight())
				paintvalue7 = getHeight();
			if(wp7 == getHeight())
				wp7 = getHeight();
			paintvalue8 += 2;
			wp8 += 1;
			if(paintvalue8 == getHeight())
				paintvalue8 = getHeight();
			if(wp8 == getHeight())
				wp8 = getHeight();
			paintvalue9 += 2;
			wp9 += 1;
			if(paintvalue9 == getHeight())
				paintvalue9 = getHeight();
			if(wp9 == getHeight())
				wp9 = getHeight();
			paintvalue10 += 2;
			wp10 += 1;
			if(paintvalue10 == getHeight())
				paintvalue10 = getHeight();
			if(wp10 == getHeight())
				wp10 = getHeight();
			paintvalue11 += 2;
			wp11 += 1;
			if(paintvalue11 == getHeight())
				paintvalue11 = getHeight();
			if(wp11 == getHeight())
				wp11 = getHeight();
			paintvalue12 += 2;
			wp12 += 1;
			if(paintvalue12 == getHeight())
				paintvalue12 = getHeight();
			if(wp12 == getHeight())
				wp12 = getHeight();
			paintvalue13 += 2;
			wp13 += 1;
			if(paintvalue13 == getHeight())
				paintvalue13 = getHeight();
			if(wp13 == getHeight())
				wp13 = getHeight();
			paintvalue14 += 2;
			wp14 += 1;
			if(paintvalue14 == getHeight())
				paintvalue14 = getHeight();
			if(wp14 == getHeight())
				wp14 = getHeight();
			paintvalue15 += 2;
			wp15 += 1;
			if(paintvalue15 == getHeight())
				paintvalue15 = getHeight();
			if(wp15 == getHeight())
				wp15 = getHeight();
			paintvalue16 += 2;
			wp16 += 1;
			if(paintvalue16 == getHeight())
				paintvalue16 = getHeight();
			if(wp16 == getHeight())
				wp16 = getHeight();
			paintvalue17 += 2;
			wp17 += 1;
			if(paintvalue17 == getHeight())
				paintvalue17 = getHeight();
			if(wp17 == getHeight())
				wp17 = getHeight();
			paintvalue18 += 2;
			wp18 += 1;
			if(paintvalue18 == getHeight())
				paintvalue18 = getHeight();
			if(wp18 == getHeight())
				wp18 = getHeight();
			paintvalue19 += 2;
			wp19 += 1;
			if(paintvalue19 == getHeight())
				paintvalue19 = getHeight();
			if(wp19 == getHeight())
				wp19 = getHeight();
			paintvalue20 += 2;
			wp20 += 1;
			if(paintvalue20 == getHeight())
				paintvalue20 = getHeight();
			if(wp20 == getHeight())
				wp20 = getHeight();
			try{		
				Thread.sleep(40);		
			}
			catch(Exception e){}
			repaint();
		}		
	}
	public void Start(){
		ready = false;
		try{
			player.start();
		}catch(Exception e){}					
		removeCommand(play);			
		addCommand(pause);			
	}
	public void Pause(){	
		ready = true;	
		try{
			player.stop();
		}catch(Exception e){}						
		removeCommand(pause);
		addCommand(play);			
	}
	public void playerUpdate(Player player, String event, Object evenData){
		if(event == (PlayerListener.END_OF_MEDIA)){				
			removeCommand(pause);
			addCommand(play);
			repeattime --;
			numplayback.setString(Integer.toString(repeattime));
			if(repeattime < 0)
				repeattime = 0;
			checkNum();	
			st = true;	
		}		
	}	
	public void checkNum(){
		if(repeattime  > 0)
			Start();
		else if(repeattime == 0){
			if(shutdown.isSelected(0) == true)	
				filemanager.exit();
		}
	}
	public void commandAction(Command c, Displayable d){
		if(c == play)
			Start();		
		if(c == pause)
			Pause();
		if(c == back){		
			list.addAudioCommand(this);
			display.setCurrent(list);
		}
		if(c == ok){			
			if((numplayback.size() == 0)||(Integer.parseInt(numplayback.getString()) < 1)){
				filemanager.showAlert("So lan phat lai phai lon hon 0 !", optionform);
			}
			else
				repeattime = Integer.parseInt(numplayback.getString());		
			display.setCurrent(this);		
		}
		if(c == option)
			display.setCurrent(optionform);
		if(c == cancel){
			display.setCurrent(this);
		}			
	}	
}